package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC1601 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        int[][] rs;

        public int maximumRequests(int n, int[][] requests) {
            rs = requests;
            int m = rs.length, ans = 0;
            for (int i = 0; i < (1 << m); i++) {
                int cnt = getCnt(i);
                if (cnt <= ans) continue;
                if (check(i)) ans = cnt;
            }
            return ans;
        }

        boolean check(int s) {
            int[] cnt = new int[20];
            int sum = 0;
            for (int i = 0; i < 16; i++) {
                if (((s >> i) & 1) == 1) {
                    int a = rs[i][0], b = rs[i][1];
                    if (++cnt[a] == 1) sum++;
                    if (--cnt[b] == 0) sum--;
                }
            }
            return sum == 0;
        }

        int getCnt(int s) {
            int ans = 0;
            for (int i = s; i > 0; i -= (i & -i)) ans++;
            return ans;
        }
    }


    public void run() {
        Solution solution = new Solution();
        int[] arr = InputUtil.toIntegerArray("[1,2,3]");
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC1601 an = new LC1601();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
